package com.example.tonyzxb.autoemulator;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by tony.zxb on 2015/12/9.
 */

public class AidlFragment extends Fragment implements View.OnClickListener {
    
    Button btnTtsStreamType;
    @Bind(R.id.listView)
    ListView lvMsg;
    private Activity mActivity;
    private ArrayList<String> msgList=new ArrayList<String>();
    private MsgAdapter msgAdapter;

    public static AidlFragment newInstance() {

        Bundle args = new Bundle();
        AidlFragment fragment = new AidlFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // return super.onCreateView(inflater, container, savedInstanceState);
        View view = View.inflate(getActivity(), R.layout.main_fg, null);
        ButterKnife.bind(this, view);
        
        mActivity=this.getActivity();
        btnTtsStreamType.setOnClickListener(this);
        msgAdapter = new MsgAdapter();
        lvMsg.setAdapter(msgAdapter);
        lvMsg.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

public static void start(Context context) {
    Intent starter = new Intent(context, AidlFragment.class);
//    starter.putExtra();
    context.startActivity(starter);
}

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
         
            default:
                break;
        }
    }
    
    class MsgAdapter extends BaseAdapter{


        @Override
        public int getCount() {
            return msgList.size();
        }

        @Override
        public Object getItem(int position) {
            return msgList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView=View.inflate(mActivity, R.layout.main_fg_item, null);
            String msg = msgList.get(position);
            ((TextView)convertView).setText(msg);
            return convertView;
        }
    }
}
